package com.tehui.utils.web;

import com.lzy.okgo.OkGo;
import com.lzy.okgo.cache.CacheMode;
import com.lzy.okgo.callback.StringCallback;

/**
 * Created by jasmine on 2017/6/16.
 */

//网络请求
public class NR {

    /**
     * @param url
     *         网络连接
     * @param key
     *         关键字
     * @param value
     *         值
     * @param callback
     *         回调
     * @param tag
     *         标示
     */
    public static void postRequest(String url, String key, String value, Object tag, StringCallback
            callback) {
        OkGo.post(url).tag(tag).params(key, value).cacheKey("cacheKey").cacheMode(CacheMode.DEFAULT)
                .execute(callback);
    }

    /**
     * @param url
     *         网络连接
     * @param callback
     *         回调
     * @param tag
     *         标示
     */
    public static void getRequest(String url, Object tag, StringCallback callback) {
        OkGo.get(url).tag(tag).cacheKey("cacheKey").cacheMode(CacheMode.DEFAULT).execute(callback);
    }

    public static void cancelTag(Object tag) {
        OkGo.getInstance().cancelTag(tag);
    }

    public static void cancelAll() {
        OkGo.getInstance().cancelAll();
    }
}
